package com.ruoyi.project.system.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.KnowledgeCatalog;
import com.ruoyi.project.system.service.IKnowledgeArticleService;
import com.ruoyi.project.system.service.IKnowledgeCatalogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 安全常识目录Controller  安全类别
 * 
 * @author ruoyi
 * @date 2020-10-07
 */
@RestController
@RequestMapping("/system/knowledgeCatalog")
public class KnowledgeCatalogController extends BaseController
{
    @Autowired
    private IKnowledgeCatalogService knowledgeCatalogService;

    @Autowired
    private IKnowledgeArticleService knowledgeArticleService;

    /**
     * 查询安全常识目录列表
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:list')")
    @GetMapping("/list")
    public TableDataInfo list(KnowledgeCatalog knowledgeCatalog)
    {
        startPage();
        List<KnowledgeCatalog> list = knowledgeCatalogService.selectKnowledgeCatalogList(knowledgeCatalog);
        return getDataTable(list);
    }

    /**
     * 导出安全常识目录列表
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:export')")
    @Log(title = "安全常识目录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(KnowledgeCatalog knowledgeCatalog)
    {
        List<KnowledgeCatalog> list = knowledgeCatalogService.selectKnowledgeCatalogList(knowledgeCatalog);
        ExcelUtil<KnowledgeCatalog> util = new ExcelUtil<KnowledgeCatalog>(KnowledgeCatalog.class);
        return util.exportExcel(list, "catalog");
    }

    /**
     * 获取安全常识目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(knowledgeCatalogService.selectKnowledgeCatalogById(id));
    }

    /**
     * 新增安全常识目录
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:add')")
    @Log(title = "安全常识目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KnowledgeCatalog knowledgeCatalog)
    {
        knowledgeCatalog.setCreateTime(new Date());
        return toAjax(knowledgeCatalogService.insertKnowledgeCatalog(knowledgeCatalog));
    }

    /**
     * 修改安全常识目录
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:edit')")
    @Log(title = "安全常识目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KnowledgeCatalog knowledgeCatalog)
    {
        return toAjax(knowledgeCatalogService.updateKnowledgeCatalog(knowledgeCatalog));
    }

    /**
     * 删除安全常识目录
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:remove')")
    @Log(title = "安全常识目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(knowledgeCatalogService.deleteKnowledgeCatalogByIds(ids));
    }


    /**
     * 获取类别下拉  getSortList
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:query')")
    @GetMapping(value = "/getSortList")
    public AjaxResult getSortList()
    {
        return AjaxResult.success(knowledgeArticleService.selectKnowledgeCatList());
    }


}
